package com.zhao.demo.bound.demo03_srctarget_diff2

import org.apache.flink.api.scala.ExecutionEnvironment
import org.apache.flink.core.fs.FileSystem

/**
 * Description: 计算指定源目录下所有文件中单词出现的次数(源->本地(Windows),目的地->hdfs)<br/>
 * Copyright (c) ，2020 ， 赵 <br/>
 * This program is protected by copyright laws. <br/>
 * Date： 2020/11/25 8:59
 *
 * @author 柒柒
 * @version : 1.0
 */

object BoundedFlowDemo2 {
  def main(args: Array[String]): Unit = {

    //1.环境准备
    val env: ExecutionEnvironment = ExecutionEnvironment.getExecutionEnvironment

    //2.计算
    //a)导入单例类中scala隐式成员
    import org.apache.flink.api.scala._

    env.readTextFile("a_input")
      .flatMap(_.split("\\s+"))
      .filter(_.nonEmpty)
      .map((_,1))
      .groupBy(0)
      .sum(1)
      .writeAsText("hdfs://ns1/flink/output/result.txt",FileSystem.WriteMode.OVERWRITE)
      .setParallelism(1)

  }
}
